< previous page page_360 next page >

Page 360
The POINT structure shows another form of the typedef statement. The official name of the structure is tagPOINT, but if you use tagPOINT in your C code it must always be preceded by the word ''struct," as follows:
struct tagPOINT myStruct;
By using the typedef version, you can declare a structure variable as follows:
POINT myStruct.
PPOINT, NPPOINT, and LPPOINT are all pointers to POINT structures.
Another common structure you will use is the RECT structure, which is defined in Visual Basic as follows:
Type RECT
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
End Type
The RECT structure describes the points of a rectangle.
Now consider the declaration of the PtInRect function shown below, which can be used to determine if a particular POINT is within a specified rectangle:
PtInRect(CONST RECT *lprc, POINT pt);
The first parameter is easy to understand. The CONST can be ignored by VB programmersit just means that the function will not be modifying the contents of the RECT structure passed as a parameter. The RECT * indicates that lprc is a pointer to a RECT structure. The Visual Basic equivalent will be to pass the RECT structure by reference.
But what about the POINT parameter? There is no pointer indication, so it looks like the entire structure needs to be passed by value. Visual Basic cannot pass structures by value, so we have a problem.
To see the solution, take a look at the stack frame in Figure T7-1. The organization of data within structures always places the first fields in the lowest memory. Since the stack grows toward lower memory, a structure passed by value will be organized as shown in the figure, with the X field appearing at a higher location (lower memory address) than the Y field. If the idea of a stack growing toward lower memory is confusing, you might want to review Tutorial 4, "How DLL Calls Work: Inside a Stack Frame."

 
< previous page page_360 next page >